package com.wxzz.elearing.user.api.admin;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.CommonCategoryDto;
import com.wxzz.elearing.user.dto.DocentDto;
import com.wxzz.elearing.user.entity.CommonCategory;
import com.wxzz.elearing.user.entity.Docent;
import com.wxzz.elearing.user.service.ICommonCategoryService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 通用分类 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-01
 */
@RestController
@RequestMapping("/common-category")
@Api(tags = "通用分类(后台)")
public class CommonCategoryController {

    @Autowired
    private ICommonCategoryService commonCategoryService;

    @ApiOperation(value = " 列出讲师分类(后台)", notes = " 列出讲师分类(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listCommonCategoryByType/{categoryType}", method = RequestMethod.POST)
    public ReturnVO<List<CommonCategory>> listCommonCategoryByType(@ApiParam("0-企业行业分类") @PathVariable Integer categoryType) {
        return commonCategoryService.listCommonCategoryByType(categoryType);
    }

    @ApiOperation(value = " 新增或修改讲师分类(后台)", notes = " 新增或修改讲师分类(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "saveCommonCategoryByType", method = RequestMethod.POST)
    public ReturnVO saveCommonCategoryByType(@RequestBody CommonCategory commonCategory) {
        commonCategory.setCategoryType(0);
        return commonCategoryService.saveCommonCategoryByType(commonCategory);
    }

    @ApiOperation(value = " 删除通用分类(后台)", notes = " 删除通用分类(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "deleteCommonCategoryById/{commonCategoryId}", method = RequestMethod.POST)
    public ReturnVO deleteCommonCategoryById(@PathVariable Long commonCategoryId) {
        return commonCategoryService.deleteCommonCategoryById(commonCategoryId);
    }

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "新增或修改改善类别(后台)", notes = " 新增或修改改善类别(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "saveCommonCategoryImprove", method = RequestMethod.POST)
    public ReturnVO saveCommonCategoryImprove(@RequestHeader String token, @RequestBody CommonCategory commonCategory) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        commonCategory.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        commonCategory.setCategoryType(1);
        return commonCategoryService.saveCommonCategoryByType(commonCategory);
    }

    @ApiOperation(value = "列出改善分类(后台)", notes = " 列出改善分类(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listCommonCategory", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<CommonCategory>>> listCommonCategory(@RequestHeader String token,@RequestBody CommonCategoryDto commonCategoryDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        commonCategoryDto.setCategoryType(1);
        commonCategoryDto.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return commonCategoryService.listCommonCategory(commonCategoryDto);
    }

    @ApiOperation(value = "平台列出企业改善分类(后台)", notes = " 平台列出企业改善分类(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listCommonCategory4platform", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<CommonCategory>>> listCommonCategory4platform(@RequestHeader String token,@RequestBody CommonCategoryDto commonCategoryDto) {
        commonCategoryDto.setCategoryType(1);
        return commonCategoryService.listCommonCategory(commonCategoryDto);
    }

    @ApiOperation(value = " 新增或修改通知等级(后台)", notes = " 新增或修改通知等级(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "saveCommonCategoryByType4Level", method = RequestMethod.POST)
    public ReturnVO saveCommonCategoryByType4Level(@RequestBody CommonCategory commonCategory) {
        commonCategory.setCategoryType(2);
        return commonCategoryService.saveCommonCategoryByType(commonCategory);
    }

    @ApiOperation(value = " 列出通知等级(后台)", notes = " 列出改善分类(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listCommonCategory4Level", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<CommonCategory>>> listCommonCategory4Level(@RequestBody CommonCategoryDto commonCategoryDto) {
        commonCategoryDto.setCategoryType(2);
        return commonCategoryService.listCommonCategory(commonCategoryDto);
    }

}
